package testAndSomeTries.motionDetection;
import java.awt.*;
import java.awt.event.*;

import javax.imageio.ImageIO;
import javax.swing.*;

import java.awt.image.*;
import java.io.File;
import java.io.IOException;

public class Testttt extends JFrame
{
	private JPanel container = new JPanel();
	
	//Display parameters
	JButton buttonPlay = new JButton("Play");
	JLabel labelInt = new JLabel("Interface");
	JLabel labelOpt = new JLabel("Options");
	JLabel labelCal = new JLabel("Calibration");
	JLabel labelGame = new JLabel("Game");
	
	JPanel panelGame = new JPanel();
	
	Image image = null;
	
	//Constructor
	public Testttt(final BufferedImage test)
	{	
		super();
		this.setSize(700, 550);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLocationRelativeTo(null);
		this.setResizable(false);		
		this.setContentPane(container);		
		this.setVisible(true);
		
		
		//Menu
		JMenuBar menu = new JMenuBar();
		JMenu menuGame = new JMenu();
		JMenu menuAbout = new JMenu();
		JMenuItem menuGameGame = new JMenuItem();
		JMenuItem menuGameCalibration = new JMenuItem();
		JMenuItem menuGameQuit = new JMenuItem();
		JMenuItem menuAboutAbout = new JMenuItem();
		
		menu.setBackground(new Color(230,30,30));
		menu.setBorder(null);
		menu.setAutoscrolls(true);
		menu.setBorderPainted(false);
		menu.setName("menu");
		menu.setOpaque(false);
		
		menuGame.setText("Game");
		menuAbout.setText("About");
		menuGameGame.setText("Game");
		menuGameCalibration.setText("Calibration");
		menuGameQuit.setText("Quit");
		menuAboutAbout.setText("About");
		
		menuGameQuit.addMouseListener(new java.awt.event.MouseAdapter()
		{
			public void mousePressed(java.awt.event.MouseEvent evt)
			{
				System.exit(0);
			}
		});
		
		menu.add(menuGame);
		menu.add(menuAbout);
		menuGame.add(menuGameGame);
		menuGame.add(menuGameCalibration);
		menuGame.add(menuGameQuit);
		menuAbout.add(menuAboutAbout);		
		setJMenuBar(menu);
		//End menu
		
		
		JPanel panelInt = new JPanel();
		JPanel panelOpt = new JPanel();
		JPanel panelCal = new JPanel();
		panelInt.setBackground(Color.GREEN);
		panelOpt.setBackground(Color.RED);
		panelCal.setBackground(Color.BLUE);
		panelGame.setBackground(Color.YELLOW);
		panelInt.setMinimumSize(new Dimension(700,50));
		panelOpt.setMinimumSize(new Dimension(200,250));
		panelCal.setMinimumSize(new Dimension(200,200));
		panelGame.setMinimumSize(new Dimension(500,450));
		panelInt.setPreferredSize(new Dimension(700,50));
		panelOpt.setPreferredSize(new Dimension(200,250));
		panelCal.setPreferredSize(new Dimension(200,200));
		panelGame.setPreferredSize(new Dimension(500,450));
		
		
		
		String name2 = System.getProperty("user.dir") + "\\testImages\\" + "back_calibration.jpg";
		java.awt.Image imag = Toolkit.getDefaultToolkit().createImage(name2);
		panelCal.removeAll();
		JLabel image = new JLabel();
		ImageIcon img = new ImageIcon(imag);	
		image.setText(null);
		image.setIcon(img);
		panelCal.add(image);
		panelCal.setVisible(true);	
		
		
		panelInt.setLayout(new GridBagLayout());
		GridBagConstraints topGBC = new GridBagConstraints();
		topGBC.gridx = 0;
		topGBC.gridy = 0;	
		panelInt.add(labelInt, topGBC);
		
		topGBC.gridx = 1;
		topGBC.gridy = 0;			
		panelInt.add(buttonPlay, topGBC);
		
		container.setLayout(new GridBagLayout());
		
		GridBagConstraints panelIntGBC = new GridBagConstraints();			
		panelIntGBC.gridx = 0;
		panelIntGBC.gridy = 0;	
		panelIntGBC.gridwidth = 14;
		panelIntGBC.gridheight = 1;
		panelIntGBC.fill = GridBagConstraints.BOTH;
		panelIntGBC.anchor = GridBagConstraints.NORTHWEST;
		container.add(panelInt, panelIntGBC);
		
		
		panelGame.add(labelGame);
		GridBagConstraints panelGameGBC = new GridBagConstraints();	
		panelGameGBC.gridx = 0;
		panelGameGBC.gridy = 1;
		panelGameGBC.gridwidth = 10;
		panelGameGBC.gridheight = 11;
		panelGameGBC.fill = GridBagConstraints.BOTH;
		panelGameGBC.anchor = GridBagConstraints.NORTHWEST;
		container.add(panelGame, panelGameGBC);
		
		
		panelOpt.add(labelOpt);
		GridBagConstraints panelOptGBC = new GridBagConstraints();	
		panelOptGBC.gridx = 10;
		panelOptGBC.gridy = 1;
		panelOptGBC.gridwidth = 4;
		panelOptGBC.gridheight = 5;
		panelOptGBC.fill = GridBagConstraints.BOTH;
		panelOptGBC.anchor = GridBagConstraints.NORTHWEST;
		container.add(panelOpt, panelOptGBC);
			
		panelCal.add(labelCal);
		GridBagConstraints panelCalGBC = new GridBagConstraints();	
		panelCalGBC.gridx = 10;
		panelCalGBC.gridy = 8;
		panelCalGBC.gridwidth = 4;
		panelCalGBC.gridheight = 4;
		panelCalGBC.fill = GridBagConstraints.BOTH;
		panelCalGBC.anchor = GridBagConstraints.NORTHWEST;
		container.add(panelCal, panelCalGBC);	
		
		
		ActionListener actionButtonPlay = new ActionListener()
		{
			public void actionPerformed(ActionEvent evt)
			{
				java.awt.Image imag = Toolkit.getDefaultToolkit().createImage(test.getSource());
				panelGame.removeAll();
				JLabel image = new JLabel();
				ImageIcon img = new ImageIcon(imag);	
				image.setText(null);
				image.setIcon(img);
				panelGame.add(image);
				panelGame.setVisible(true);
				panelGame.revalidate();	

			}
		};
		
		buttonPlay.addActionListener(actionButtonPlay);	
	}
	
	
	public static void main(String[] args)
	{
		BufferedImage buf_1 = null;
		BufferedImage buf_2 = null;
		
		//Read background image
		String name = System.getProperty("user.dir") + "\\testImages\\" + "fg.jpg";	
		try {
			buf_1 = ImageIO.read(new File(name));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
			
		//Read foreground image
		name = System.getProperty("user.dir") + "\\testImages\\" + "fg.jpg";
		try {
			buf_2 = ImageIO.read(new File(name));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		
		ObjectTracking object = new ObjectTracking(buf_1, buf_2);
//		/BufferedImage buffff = object.getBuf();
		int[] coord = object.getGrav();
		System.out.println("coordonates: abs: " + coord[0] + " ord: " + coord[1] + "\n");
		//Testttt test = new Testttt(buffff);
	}

}
